home *** CD-ROM | disk | FTP | other *** search
- Path: cliffy.lfwc.lockheed.com!news
- From: James Bassett <bassett@flash.net>
- Newsgroups: comp.lang.c++
- Subject: Solved memory leak BUT new question!!!
- Date: 23 Feb 1996 19:55:37 GMT
- Organization: Computer Science Corp.
- Message-ID: <4gl63p$fpb@cliffy.lfwc.lockheed.com>
- NNTP-Posting-Host: 11200855.-pcimport.lfwc.lockheed.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
-
- Here is the original problem:
-
- I am using Visual C++ 1.51 under Windows 3.1. Using an ODBC recordset and
- creating an instance of the set using the _new_ operator and then
- deleting the object with the _delete_ operator. But we lose the same
- amount of memory each time. Anyone know how to recover the lost memory or
- what are we doing wrong?
-
- Below is an example:
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CPlotDefset recordset
-
- class CPlotDefset : public CRecordset
- {
-
- public:
- CPlotDefset(CDatabase* pDatabase = NULL);
-
-
- In another .h file a pointer is declared:
-
- //
- //
- CPlotDefset *plotdef_set; //Plot defintion set
-
-
- Then in a dialog box routine the following is done:
-
- //
- //
- plotdef_set = new CPlotDefset; //Get an instance of plot
- definition set
-
- plotdef_set->Open(); //Open the database set
-
- //
-
- CPlotEx dlg; //Dialog for existing plots
-
- if(dlg.DoModal() == IDOK)
- {
- plotdef_set->Close();
- delete plotdef_set; //delete the plot
- defintion set
-
- Invalidate();
- }
- }
-
- After doing the delete plotdef_set not all of the memory is released.
-
- I hope someone can help!!
-
- Jim Bassett
- bassett@flash.net
-
-
-
- Later I change the parameter plotdef_set from bring a pointer to just an
- object. This made the memory leak go away!! Question... WHY????
-
- Below is the rewritten code:
-
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CPlotDefset recordset
-
- class CPlotDefset : public CRecordset
- {
-
- public:
- CPlotDefset(CDatabase* pDatabase = NULL);
-
-
- In another .h file a pointer is declared:
-
- //
- //
- CPlotDefset *plotdef_set; //Plot defintion set
-
-
- Then in a dialog box routine the following is done:
-
- //
- //
-
- plotdef_set.Open(); //Open the database set
-
- //
-
- CPlotEx dlg; //Dialog for existing plots
-
- if(dlg.DoModal() == IDOK)
- {
- plotdef_set.Close();
-
-
- Invalidate();
- }
- }
-
-
- I would think this should not correct this!
-
-
-
- I hope someone can answer this one!!
-
- Jim Bassett
-
-